home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
system
/
epuptm17.zip
/
DVUPTIME.C
next >
Wrap
C/C++ Source or Header
|
1994-01-27
|
2KB
|
97 lines
#ifndef __TINY__
#error Use TINY memory model--Don't forget to turn off debug info
#endif
#include <stdio.h>
#include <dos.h>
#include <dir.h>
#include <time.h>
#include <stdlib.h>
void
main(void);
void
writeout(void);
char filename[255];
struct ffblk ffblk;
struct time curtime;
struct date curdate;
struct tm old, *new;
time_t thetime;
int sec, min, day, hour;
char bday[4], bmon[4], ampm = 'a';
int bdate, bhour, bmin, bsec, byear;
void
main(void)
{
strcpy(filename, searchpath("uptime.exe"));
writeout();
printf("\n\nStrike Any Key To Continue...");
fcloseall();
getch();
} /* main */
void
writeout(void)
{
char tz[257],*oldtz;
tz[0]='\0';
oldtz=getenv("TZ");
if(oldtz!=NULL){
strcat(tz,"TZ=");
putenv(tz);
}
findfirst(filename, &ffblk, FA_DIREC);
old.tm_sec = 2 * (ffblk.ff_ftime & 31);
old.tm_min = (ffblk.ff_ftime & 2016) >> 5;
old.tm_hour = (ffblk.ff_ftime & 63488) >> 11;
old.tm_mday = (ffblk.ff_fdate & 31);
old.tm_mon = ((ffblk.ff_fdate & 480) >> 5) - 1;
old.tm_year = ((ffblk.ff_fdate & 65024) >> 9) + 80;
mktime(&old);
thetime = time(NULL);
new = localtime(&thetime);
sec = (*new).tm_sec - old.tm_sec;
min = (*new).tm_min - old.tm_min;
if (sec < 0) {
sec += 60;
min--;
}
hour = (*new).tm_hour - old.tm_hour;
if (min < 0) {
min += 60;
hour--;
}
day = (*new).tm_yday - old.tm_yday + (365 * ((*new).tm_year - old.tm_year));
if (hour < 0) {
hour += 24;
day--;
}
sscanf(asctime(&old), "%3s %3s %d %d:%d:%d %d", bday, bmon, &bdate, &bhour, &bmin, &bsec, &byear);
if (bhour >= 12) {
bhour -= 12;
ampm = 'p';
}
if (bhour == 0)
bhour = 12;
if (day < 0)
printf("Error: System clock has been changed since bootup");
else if (day != 0)
printf("System launched at %2.2d:%2.2d:%2.2d%cm on %s, %s %d, %d\nUp for %d day(s), %2.2d:%2.2d:%2.2d", bhour, bmin, bsec, ampm, bday, bmon, bdate, byear, day, hour, min, sec);
else
printf("System launched at %2.2d:%2.2d:%2.2d%cm on %s, %s %d, %d\nUp for %2.2d:%2.2d:%2.2d", bhour, bmin, bsec, ampm, bday, bmon, bdate, byear, hour, min, sec);
if(oldtz!=NULL){
strcpy(tz,oldtz);
putenv(tz);
}
}